//版权申明
//北大词酷系统接口包
//北京大学计算语言学研究所
//刘扬
//liuyang@pku.edu.cn
//2015.8.6版本
package search.helper.language;

import java.io.*;
import java.util.*;

public class SemanticDict
{  static int positionMax=100000;
   static int wordMax=200000;
   static String[] positionWordList_Position=null;
   static String[][] positionWordList_Word=null;
   static String[] wordPositionList_Word=null;
   static String[][] wordPositionList_Position=null;

   //服务于API接口的私有方法,普通用户不建议调用
   private String[] getStringList(String blankedStr)
   {  if (blankedStr==null)
		 return null;
	  else
	  {  String tempStr=blankedStr+" ";
	     int blks=0;
	     for (int i=0;i<tempStr.length();i=i+1)
		    if (tempStr.substring(i,i+1).equals(" "))
	           blks=blks+1;
	     String[] strList=new String[blks];
	     for (int i=0;i<blks;i=i+1)
	     {  int blkPos=tempStr.indexOf(" ");
	        strList[i]=tempStr.substring(0,blkPos);
		    tempStr=tempStr.substring(blkPos+1);
	     }
		 strList=getSortedSet(strList);
	     return strList;
	  }
   }

   //服务于API接口的私有方法,普通用户不建议调用
   private String[] getSortedSet(String[] strList)
   {  Arrays.sort(strList);
      String[] tempList=new String[strList.length];
	  int idx=0;
	  tempList[idx]=strList[0];
	  String previous=strList[0];
	  for (int i=1;i<strList.length;i=i+1)
	  {  String current=strList[i];
	     if (!(current.equals(previous)))
	     {  idx=idx+1;
		    tempList[idx]=strList[i];
		    previous=current;
		 }
	  }
	  String[] sortedSet=Arrays.copyOfRange(tempList,0,idx+1);
	  return sortedSet;
   }

   //服务于API接口的私有方法,普通用户不建议调用
   //返回word出现的position列表
   private String[] getPositionList(String word)
   {  int idx=Arrays.binarySearch(wordPositionList_Word,word);
      if (idx<0)
		 return null;
	  else
	     return wordPositionList_Position[idx];
   }

   //服务于API接口的私有方法,普通用户不建议调用
   //返回position对应的同义词集
   private String[] getWordList(String position)
   {  int idx=Arrays.binarySearch(positionWordList_Position,position);
	  if (idx<0)
		 return null;
	  else
	     return positionWordList_Word[idx];
   }

   //加载词库文件,API接口初使化,加载异常时控制台报错
   public void loadLexicon(String lexiconFile)//to be simplified
   {  String[] positionWordList;
      String[] wordPositionList;
      String[] tempPositionWordList=new String[positionMax];
      String[] tempWordPositionList=new String[wordMax];
      String line;
	  int posIdx=-1;
	  int wrdIdx=-1;
      try
      {  BufferedReader lexiconReader=new BufferedReader(new FileReader(lexiconFile));
	     while ((line=lexiconReader.readLine())!=null)
         {  int at=line.indexOf("@");
	        if (at<0)
			{  posIdx=posIdx+1;
		       tempPositionWordList[posIdx]=line;
			}
			else
			{  String word=line.substring(0,at);
		       tempPositionWordList[posIdx]=tempPositionWordList[posIdx]+" "+word;
		       wrdIdx=wrdIdx+1;
			   int bl=tempPositionWordList[posIdx].indexOf(" ");
			   String position=tempPositionWordList[posIdx].substring(0,bl);
		       tempWordPositionList[wrdIdx]=word+" "+position;
			}
         }
		 positionWordList=Arrays.copyOfRange(tempPositionWordList,0,posIdx+1);
		 positionWordList_Position=new String[positionWordList.length];
		 positionWordList_Word=new String[positionWordList.length][];
		 for (int i=0;i<positionWordList.length;i=i+1)
		 {  int bl=positionWordList[i].indexOf(" ");
	        positionWordList_Position[i]=positionWordList[i].substring(0,bl);
			positionWordList_Word[i]=getStringList(positionWordList[i].substring(bl+1));
		 }
		 String[] sortedWordPositionList=Arrays.copyOfRange(tempWordPositionList,0,wrdIdx+1);
		 Arrays.sort(sortedWordPositionList);
		 String[] setedWordPositionList=new String[sortedWordPositionList.length];
		 int setIdx=0;
		 setedWordPositionList[setIdx]=sortedWordPositionList[0];
		 int bl=sortedWordPositionList[0].indexOf(" ");
		 String previous=sortedWordPositionList[0].substring(0,bl);
		 for (int i=1;i<sortedWordPositionList.length;i=i+1)
		 {  bl=sortedWordPositionList[i].indexOf(" ");
		    String current=sortedWordPositionList[i].substring(0,bl);
			if (current.equals(previous))
			   setedWordPositionList[setIdx]= setedWordPositionList[setIdx]+" "+sortedWordPositionList[i].substring(bl+1);
		    else
			{  setIdx=setIdx+1;
		       setedWordPositionList[setIdx]=sortedWordPositionList[i];
			   previous=current;
			}
	     }
		 wordPositionList=Arrays.copyOfRange( setedWordPositionList,0,setIdx+1);
		 wordPositionList_Word=new String[wordPositionList.length];
		 wordPositionList_Position=new String[wordPositionList.length][];
		 for (int i=0;i<wordPositionList.length;i=i+1)
		 {  bl=wordPositionList[i].indexOf(" ");
	        wordPositionList_Word[i]=wordPositionList[i].substring(0,bl);
			wordPositionList_Position[i]=getStringList(wordPositionList[i].substring(bl+1));
		 }
         lexiconReader.close();
      }
      catch(Exception e)
      {  e.printStackTrace();
      }
   }

   //////////////////////////////////
   /*
   * 返回词表
   */
   //输出词库全部词表,返回至一维数组,异常返回值null
   public String[] getVocabulary()
   {  if (wordPositionList_Word==null)
	     return null;
	  else
         return wordPositionList_Word;
   }

   //输出特定词性词表,返回至一维数组,异常返回值null
   public String[] getVocabulary(String POSName)
   {  //String[] POSNames={"noun","noun","noun","noun","noun","noun","noun","noun","noun","noun","noun","noun","noun","noun"};
      String[] POSNames={"noun"};
      //String[] POSTags= {"0001","0002","0003","0004","0005","0006","0007","0008","0009","0010","0011","0012","0013","0014"};
      String[] POSTags= {"0001"};
	  int idx=-1;
	  for (int i=0;i<POSNames.length;i=i+1)
	     if (POSNames[i].equals(POSName))
		 {  idx=i;
	        break;
		 }
	  if (idx<0)
		 return null;
	  else
	  {  String[] tempWordList=new String[wordPositionList_Word.length];
	     int ct=0;
	     for (int i=0;i<wordPositionList_Word.length;i=i+1)
	        for (int j=0;j<wordPositionList_Position[i].length;j=j+1)
		       //if (wordPositionList_Position[i][j].startsWith("0001"+POSTags[idx]))
			   if (wordPositionList_Position[i][j].startsWith(POSTags[idx]))
	           {  tempWordList[ct]=wordPositionList_Word[i];
		          ct=ct+1;
				  break;
               }
		 String[] wordList=Arrays.copyOfRange(tempWordList,0,ct);
	     return wordList;
	  }
   }

   //////////////////////////////////
   /*
   *  返回同义词集
   */
   //输出同义词集,返回至二维数组,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getSynonyms(String word)
   {  String[] posList=getPositionList(word);
	  int len=posList.length;
	  if (len<0)
	     return null;
	  else
	  {  String[][] synonyms=new String[len][];
		 for (int i=0;i<len;i=i+1)
		    synonyms[i]=getWordList(posList[i]);
		 return synonyms;
	  }
   }

   public String[][] getAllSynonyms(){
   	   int len = positionWordList_Position.length;
       String[][] synonyms=new String[len][];
       String[] tmp = null;
       for(int i=0;i<len;i++){
       	   tmp = getWordList(positionWordList_Position[i]);
       	   synonyms[i] = new String[tmp.length+1];
       	   synonyms[i][0] = positionWordList_Position[i];
       	   for(int j = 0; j < tmp.length; j++)
       	   	   synonyms[i][j+1] = tmp[j];
       }
       return synonyms;
   }

   public void outputAllSynonyms(){
   	  String[][] synonyms = getAllSynonyms();
	  fileOutputSyn("AllSynonyms.txt",synonyms);
   }

   //////////////////////////////////
   /*
   * 返回近义词集
   */
   //输出位置相似度,正常返回值[0.0f,1.0f],异常返回值-1.0f
   public float getPositionSimilarity(String position1,String position2)
   {  float similarity=-1.0f;
      int idx1=Arrays.binarySearch(positionWordList_Position,position1);
	  int idx2=Arrays.binarySearch(positionWordList_Position,position2);
	  if ((idx1<0) || (idx2<0))
		 return similarity;
      else
      {	 int len1=position1.length()/4;
	     int len2=position2.length()/4;
	     int lenMin=(len1<=len2)?len1:len2;
	     int stem=0;
	     while ((stem<lenMin) && (position1.substring(stem*4,stem*4+4).equals(position2.substring(stem*4,stem*4+4))))
		    stem=stem+1;
	     similarity=(float)(2*stem)/(float)(len1+len2);
	     return similarity;
	  }
   }

   //输出词语相似度,正常返回值[0.0f,1.0f],异常返回值-1.0f
   public float getWordSimilarity(String word1,String word2)
   {  float similarity=-1.0f;
      String[] posList1=getPositionList(word1);
	  String[] posList2=getPositionList(word2);
	  int len1=posList1.length;
      int len2=posList2.length;
	  if ((len1>0) && (len2>0))
	     for (int i=0;i<len1;i=i+1)
	     {  String position1=posList1[i];
		    for (int j=0;j<len2;j=j+1)
	        {  String position2=posList2[j];
		       float sim=getPositionSimilarity(position1,position2);
			   if (sim>similarity)
			      similarity=sim;
		    }
	     }
	  return similarity;
   }

   //输出近义词集,需要设定词语相似度参数,返回至二维数组,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getSimilars(String word,float threshold)//synset & order
   {  String[] posList=getPositionList(word);
	  if (posList==null)
	     return null;
	  else
	  {  int len=posList.length;
         String[][] similars=new String[len][];
         for (int i=0;i<len;i=i+1)
         {  String[] tempWordList=new String[wordMax];
		    int ct=0;
		    for (int j=0;j<positionWordList_Position.length;j=j+1)
		       if (getPositionSimilarity(posList[i],positionWordList_Position[j])>=threshold)
		       {  String[] synList=getWordList(positionWordList_Position[j]);
				  int synLen=synList.length;
				  for (int k=0;k<synLen;k=k+1)
				     tempWordList[ct+k]=synList[k];
			      ct=ct+synLen;
		       }
		    String[] wordList=Arrays.copyOfRange(tempWordList,0,ct);
			wordList=getSortedSet(wordList);
			similars[i]=wordList;
		 }
		 return similars;
	  }
   }

   public String[][] getAllSimilars(float threshold){
      String[] posList = positionWordList_Position;
	  if (posList==null)
	     return null;
	  else
	  {  int len=posList.length;
         String[][] similars=new String[len][];
         for (int i=0;i<len;i=i+1)
         {  String[] tempWordList=new String[wordMax];
         	tempWordList[0] = posList[i];
		    int ct=1;
		    for (int j=0;j<positionWordList_Position.length;j=j+1){
		       if(i == j) continue;
		       if (getPositionSimilarity(posList[i],positionWordList_Position[j])>=threshold)
		       {  String[] synList=getWordList(positionWordList_Position[j]);
				  int synLen=synList.length;
				  for (int k=0;k<synLen;k=k+1)
				     tempWordList[ct+k]=synList[k];
			      ct=ct+synLen;
		       }
		    }
		    String[] wordList=Arrays.copyOfRange(tempWordList,0,ct);
			wordList=getSortedSet(wordList);
			similars[i]=wordList;
		 }
		 return similars;
	  }
   }

   public void outputAllSimilars(float threshold){
   	  String[][] similars = getAllSimilars(threshold);
	  fileOutputNosyn("AllSimilars-" + threshold + ".txt",similars);
   }

   //////////////////////////////////
   /*
   * 返回上义词集
   */
   //输出直接上位词集,返回至二维数组,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getDirectHypernyms(String word)
   {  return getDepthHypernyms(word,1);
   }

   //输出连续上位词集,需要指定上位深度参数,返回至二维数组,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getDepthHypernyms(String word,int depth)//set
   {  String[] posList=getPositionList(word);
      if ((posList==null) || (depth<=0))
	     return null;
	  else
	  {  int len=posList.length;
         String[][] hypernyms=new String[len][];
         for (int i=0;i<len;i=i+1)
         {  
         	//System.out.println(posList[i]);
         	int hyperLen=(posList[i].length()-4)/4;
	        hyperLen=(depth<hyperLen)?depth:hyperLen;
			if (hyperLen>0)
			{  String[] wordList=null;
			   String[] tempWordList=new String[wordMax];
			   int ct=0;
		       for (int j=1;j<hyperLen+1;j=j+1)
	           {  String hyperPos=posList[i].substring(0,posList[i].length()-4*j);
		          String[] synList=getWordList(hyperPos);
			      synList=getSortedSet(synList);
			      int synLen=synList.length;
			      //synLen=synLen+1;
			      //tempWordList[ct]=">";
			      for (int k=0;k<synLen;k=k+1)
			   	     tempWordList[ct+k]=synList[k];
			      ct=ct+synLen;
			   }
			   wordList=Arrays.copyOfRange(tempWordList,0,ct);
			   hypernyms[i]=wordList;
			}
		 }
		 return hypernyms;
	  }
   }

   //输出全部上位词集,返回至二维数组,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getFullHypernyms(String word)
   {  return getDepthHypernyms(word,100);
   }

   //输出所有词的连续上位词集
   //需要指定上位深度参数,返回至二维数组,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getAllDepthHypernyms(int depth)
   {  
   	  String[] posList = positionWordList_Position;
      if ((posList==null) || (depth<=0))
	     return null;
	  else
	  {  
	  	 int len=posList.length;
         String[][] hypernyms=new String[len][];
         int counter = 0; //标记有多少个意项有上位词
         for (int i=0;i<len;i=i+1)
         {  
         	int hyperLen=(posList[i].length()-4)/4;
	        hyperLen=(depth<hyperLen)?depth:hyperLen;
			if (hyperLen>0)
			{  
			   String[] wordList=null;
			   String[] tempWordList=new String[wordMax];
			   tempWordList[0] = posList[i];
			   int ct=1;
		       for (int j=1;j<hyperLen+1;j=j+1)
	           {  
	           	  String hyperPos=posList[i].substring(0,posList[i].length()-4*j);

		          String[] synList=getWordList(hyperPos);
			      synList=getSortedSet(synList);

			      int synLen=synList.length;
			      for (int k=0;k<synLen;k=k+1)
			   	     tempWordList[ct+k]=synList[k];
			      ct=ct+synLen;
			   }
			   wordList=Arrays.copyOfRange(tempWordList,0,ct);
			   //hypernyms[i]=wordList;
			   hypernyms[counter]=wordList;
			   counter ++;
			}
		 }
		 hypernyms = Arrays.copyOfRange(hypernyms,0,counter);
		 return hypernyms;
	  }
   }

   public void outputAllDepthHypernyms(int depth){
   	  String[][] hypernyms = getAllDepthHypernyms(depth);
	  fileOutputNosyn("AllDepthHypernyms-" + depth + ".txt",hypernyms);
   }

   //////////////////////////////////
   /*
   * 返回下义词集
   */
   //输出直接下位词集,返回至二维数组,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getDirectHyponyms(String word)
   {  return getDepthHyponyms(word,1);
   }

   //输出连续下位词集,需要指定下位深度参数,返回至二维数组,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getDepthHyponyms(String word,int depth)//synset & order
   {  
   	  String[] posList=getPositionList(word);
      if ((posList==null) || (depth<=0))
	     return null;
	  else
	  {  int len=posList.length;
         String[][] hyponyms=new String[len][];
         for (int i=0;i<len;i=i+1)
         {  String[] wordList=null;
			String[] tempWordList=new String[wordMax];
			int ct=0;
			int hypoLen=posList[i].length()/4;
	        for (int j=0;j<positionWordList_Position.length;j=j+1)
			{  int curLen=positionWordList_Position[j].length()/4;
		       if (positionWordList_Position[j].startsWith(posList[i]) && (curLen-hypoLen>0) && (curLen-hypoLen<=depth))
			   {  String[] synList=getWordList(positionWordList_Position[j]);
				  int synLen=synList.length;
			      for (int k=0;k<synLen;k=k+1)
			   	     tempWordList[ct+k]=synList[k];
			      ct=ct+synLen;
			   }
			   wordList=Arrays.copyOfRange(tempWordList,0,ct);
			   hyponyms[i]=wordList;
			}
		 }
		 return hyponyms;
	  }
   }

   //输出全部下位词集,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getFullHyponyms(String word)
   {  return getDepthHyponyms(word,100);
   }

   //输出连续下位词集
   //需要指定下位深度参数,返回至二维数组,返回数组中的两个维度分别表示义项和词集,异常返回值null
   public String[][] getAllDepthHyponyms(int depth)
   {  
   	  String[] posList= positionWordList_Position ;//getPositionList(word);
      if ((posList==null) || (depth<=0))
	     return null;
	  else
	  {  
	  	 int len=posList.length;
         String[][] hyponyms=new String[len][];
         int counter = 0;
         for (int i=0;i<len;i=i+1)
         {  
         	String[] wordList=null;
			String[] tempWordList=new String[wordMax];
			tempWordList[0] = posList[i];
			int ct=1;
			int hypoLen=posList[i].length()/4;
	        for (int j=0;j<positionWordList_Position.length;j=j+1)
			{  
			   int curLen=positionWordList_Position[j].length()/4;
		       if (positionWordList_Position[j].startsWith(posList[i]) && (curLen-hypoLen>0) && (curLen-hypoLen<=depth))
			   {  
			   	  String[] synList=getWordList(positionWordList_Position[j]);
				  int synLen=synList.length;
			      for (int k=0;k<synLen;k=k+1)
			   	     tempWordList[ct+k]=synList[k];
			      ct=ct+synLen;
			   }
			   //wordList=Arrays.copyOfRange(tempWordList,0,ct);
			   //hyponyms[i]=wordList;
			}
			wordList=Arrays.copyOfRange(tempWordList,0,ct);
			//hyponyms[i]=wordList;
			if(ct > 1){
				hyponyms[counter]=wordList;
				counter ++;
			}
		 }
		 hyponyms = Arrays.copyOfRange(hyponyms,0,counter);
		 return hyponyms;
	  }
   }

   public void outputAllDepthHyponyms(int depth){
      String[][] hyponyms = getAllDepthHyponyms(depth);
	  fileOutputNosyn("AllDepthHyponyms-" + depth + ".txt",hyponyms);
   }

   //////////////////////////////////
   /*
   * 输出至文件
   */
   //输出数据文件,将一维数组数据输出至指定文件
   public void fileOutput(String filename, String[] data)
   {  if (!(data==null))
	     try
         {  BufferedWriter dataWriter=new BufferedWriter(new FileWriter(filename));
	        for (int i=0;i<data.length;i=i+1)
	        {  dataWriter.write(data[i]);
	           dataWriter.newLine();
	        }
	        dataWriter.flush();
	        dataWriter.close();
         }
         catch(Exception e)
         {  e.printStackTrace();
         }
   }

   //输出数据文件,将二维数组数据输出至指定文件
   public void fileOutput(String filename, String[][] data)
   {  if (!(data==null))
	     try
         {  BufferedWriter dataWriter=new BufferedWriter(new FileWriter(filename));
	        for (int i=0;i<data.length;i=i+1)
	        {  for (int j=0;j<data[i].length;j=j+1)
		          dataWriter.write(data[i][j]+" ");
	           dataWriter.newLine();
	        }
	        dataWriter.flush();
	        dataWriter.close();
         }
         catch(Exception e)
         {  e.printStackTrace();
         }
   }

   //输出同义词集文件，格式1
   public void fileOutputSyn(String filename, String[][] data)
   {  
   	  if (!(data==null))
	     try
         {  
         	BufferedWriter dataWriter=new BufferedWriter(new FileWriter(filename));
         	boolean isSingle = true; //记录是否是单个词构成的同义词集
         	String line = "";
	        for (int i=0;i<data.length;i=i+1)
	        {  
	           isSingle = true;
	           line = "";
	           if(data[i][1].indexOf("_") > 0) continue;  //下划线_连接的“虚同义词集”，忽略
	           //dataWriter.write(data[i][1]);
	           line += data[i][1];
	           for (int j=2; j<data[i].length;j=j+1){
	           	  isSingle = false;
		          //dataWriter.write(","+data[i][j]);
		          line += (","+data[i][j]);
	           }
	           if(isSingle == false){
	           	  dataWriter.write(line);
	              dataWriter.newLine();
	           }
	           
	        }
	        dataWriter.flush();
	        dataWriter.close();
         }
         catch(Exception e)
         {  e.printStackTrace();
         }
   }

   //输出除同义词集外的其他文件，格式2，“=>”号分隔
   public void fileOutputNosyn(String filename, String[][] data)
   {  if (!(data==null))
	     try
         {  BufferedWriter dataWriter=new BufferedWriter(new FileWriter(filename));
         	String[] synset = null;
         	String line = ""; //带输出额每一行
         	boolean empty = true; //记录"=>"号右边是否为空
	        for (int i=0;i<data.length;i=i+1)
	        {  
	           empty = true;
	           line = "";
	           synset = getWordList(data[i][0]);
	           if(synset[0].indexOf("_") > 0) continue;
	           //dataWriter.write(synset[0]);
	           line += synset[0];
	           for (int j=1;j<synset.length;j++){
	           	  //dataWriter.write("," + synset[j]);
	           	  line += ("," + synset[j]);
	           }
	           //dataWriter.write(" => ");
	           line += " => ";
	           //if(!(data[i][1].indexOf("_") > 0))
	              //dataWriter.write(data[i][1]);
	           boolean isFirst = true;
	           for (int j=1;j<data[i].length;j=j+1){
	           	  if(data[i][j].indexOf("_") > 0) continue;
	           	  if(isFirst){
	           	  	//dataWriter.write(data[i][j]);
	           	  	line += data[i][j];
	           	  	isFirst = false;
	           	  	empty = false;
	           	  }
	           	  else{
	           	  	//dataWriter.write(","+data[i][j]);
	           	  	line += (","+data[i][j]);
	           	  }
	           }

	           if(empty == false){
	           	  dataWriter.write(line);
	              dataWriter.newLine();
	           } 
	        }
	        dataWriter.flush();
	        dataWriter.close();
         }
         catch(Exception e)
         {  e.printStackTrace();
         }
   }

   //////////////////////////////////
   /*
   * Main 函数
   */
   //API接口调用示范,除测试外,建议在单独程序中使用
   public static void main(String args[])//as demo.java
   {  
	  SemanticDict task = new SemanticDict();

      task.loadLexicon("TestData.txt");

	  //String[] words=task.getVocabulary();
      //task.fileOutput("Vocabulary.txt",words);
	  //String[] POSs=task.getVocabulary("noun");
      //task.fileOutput("noun.txt",POSs);

      //System.out.println(task.getPositionSimilarity("00010001","00010002"));
	  //System.out.println(task.getWordSimilarity("男人","女人"));
	  //System.out.println(task.getWordSimilarity("花儿","少年"));

	  //String[][] synonyms=task.getSynonyms("仪表");
	  //task.fileOutput("Synonyms.txt",synonyms);
	  task.outputAllSynonyms();

	  //String[][] similars=task.getSimilars("男人",0.5f);
	  //String[][] similars=task.getSimilars("男人",0.75f);
	  //String[][] similars=task.getSimilars("男人",1.0f);
	  //task.fileOutput("Similars.txt",similars);
	  task.outputAllSimilars(0.9f);  //当参数为0.9f时，结果几乎为空

	  //String[][] hypernyms=task.getDirectHypernyms("女人");
	  //String[][] hypernyms=task.getDepthHypernyms("女人",5);
	  //String[][] hypernyms=task.getFullHypernyms("女人");
	  //task.fileOutput("Hypernyms.txt",hypernyms);
	  task.outputAllDepthHypernyms(1);

	  //String[][] hyponyms=task.getDirectHyponyms("人");
	  //String[][] hyponyms=task.getDepthHyponyms("人",5);
	  //String[][] hyponyms=task.getFullHyponyms("人");
	  //task.fileOutput("Hyponyms.txt",hyponyms);
	  task.outputAllDepthHyponyms(1);
   }
}
